package tester.outcome;

import messages.BaseMessage;

/**
 * This method is the base outcome super class
 * @author Caleb Chan
 *
 */
public abstract class BaseOutcome {

	private static final long INCOMPETE_TIME_VALUE = -1;
	
	protected BaseMessage outcomeMessage;
	
	protected long completionTime;
	protected long startTime;
	
	protected boolean isCompleted;
	/**
	 * BaseOutcome constructor
	 * @param message The message that the message from the person or group dispatcher is compared to
	 * @param startTime The start time of the test
	 */
	public BaseOutcome(BaseMessage message, long startTime){
		this.outcomeMessage = message;
		this.startTime = startTime;
		this.completionTime = INCOMPETE_TIME_VALUE;
		this.isCompleted = false;
	}
	
	/**
	 * This method will return if this outcome was found as a return message
	 * @return Returns if this outcome was completed
	 */
	public boolean getIsCompleted(){
		return this.isCompleted;
	}
	
	/**
	 * This method will return the completion time of this outcome
	 * @return Returns the completion time of this message
	 */
	public long getCompletionTime() {
		return completionTime;
	}

	/**
	 * This method will return the start time of this outcome
	 * @return Returns the start time of this outcome
	 */
	public long getStartTime() {
		return startTime;
	}
	
	/**
	 * This method will set the start time of the outcome
	 * @param startTime Set the start time of the outcome
	 */
	public void setStartTime(long startTime){
		this.startTime = startTime;
	}
	
	/**
	 * This method will get the difference between the completion time and start time
	 * @return Returns the difference between the completion time and the start time
	 */
	public long getDeltaTime(){
		return this.completionTime - this.startTime;
	}
	
	/**
	 * This method will get the difference between the completion time of the BaseOutcome provided
	 * this completion time
	 * @param outcome The outcome to be compared to
	 * @return Returns the difference the between the two outcomes
	 */
	public long getDeltaTime(BaseOutcome outcome){
		return outcome.completionTime - this.completionTime;
	}
	
	/**
	 * This method will check the to see if the base message provided was the expected message that
	 * this outcome was waiting for 
	 * @param message The message to be checked
	 * @return Returns true if the message was the same type as the one expected
	 */
	public boolean checkOutcome(BaseMessage message){
		return message.getMessageType() == outcomeMessage.getMessageType();
	}
	
	/**
	 * This method will return the outcome's name
	 * @return Returns the outcome's name
	 */
	public abstract String getOutcomeName();
	
	/**
	 * This method will return the outcome's name and the conditions that its looking for
	 * @return Return the outcome's name and conditions its looking for
	 */
	public abstract String getOutcomeChecksStr();
	/**
	 * This method will return a copy of the outcome
	 * @return Returns a copy of this outcome
	 */
	public abstract BaseOutcome copy();
}
